﻿@model SCMS.UI.Models.ViewTAForms
@{AjaxOptions ajaxOpts = new AjaxOptions
  {
      UpdateTargetId = "popup-page",
      LoadingElementId = "popup-loading",
      HttpMethod = "Post",
      Url = Url.Action("AuthorizeTAF"),
      OnBegin = "return VerifyBLBalance4TAF(" + Model.ViewTravelDates.Count + ", " + Model.ViewTravelExpenses.Count + ");",
      OnSuccess = "CenterPopup();LoadRequests();"
  };}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    
@using (Ajax.BeginForm(null, null, ajaxOpts, new { @class = "form" }))
{
    @Html.ValidationSummary(true)
    <h4 style="text-align: center;">TRAVEL AUTHORIZATION FORM</h4>
    <center><b>No. @Model.TAuthFormEntity.RefNumber</b></center>
    @Html.HiddenFor(m => m.TAuthFormEntity.Id)
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th align="center">
                Date
            </th>
            <th align="center">
                Travellers Name
            </th>
            <th align="center">
                Title
            </th>
        </tr>
        <tr>
            <td align="center">
                @Model.TAuthFormEntity.PreparedOn.Value.ToString("dd/MM/yyyy")
            </td>
            <td align="center">
                @if (Model.Travelller != null)
                {@Model.Travelller.StaffName}
                else
                { @Model.TAuthFormEntity.TravelerName}
            </td>
            <td align="center">
                @if (Model.Travelller != null)
                {@Model.Travelller.Designation}
                else
                { @Model.TAuthFormEntity.TravelerTitle}
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">
                Destination
            </th>
            <th align="center">
                Travell Type
            </th>
            <th align="center">
                Traveller Type
            </th>
        </tr>
        <tr>
            <td align="center">
                @Model.TAuthFormEntity.Destination
            </td>
            <td align="center">
                @Model.TAuthFormEntity.TravellType
            </td>
            <td align="center">
                @Model.TAuthFormEntity.TravellerType
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">
                Travel Start Date
            </th>
            <th align="center">
                Travel End Date
            </th>
            <th align="center">
                Total no. of nights
            </th>
        </tr>
        <tr>
            <td align="center">
                @Model.TAuthFormEntity.TravelStartDate.Value.ToString("dd/MM/yyyy")
            </td>
            <td align="center">
                @Model.TAuthFormEntity.TravelEndDate.Value.ToString("dd/MM/yyyy")
            </td>
            <td align="center">
                @Model.TAuthFormEntity.NoOfNights
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">
                Journey From
            </th>
            <th align="center">
                Journey To
            </th>
            <th align="center">
                Via
            </th>
        </tr>
        <tr>
            <td align="center">
                @Model.TAuthFormEntity.FromLocation
            </td>
            <td align="center">
                @Model.TAuthFormEntity.ToLocation
            </td>
            <td align="center">
                @Model.TAuthFormEntity.ViaLocation
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">
                Travel Means
            </th>
            <th align="left" colspan="2">
                TAF Currency
            </th>
        </tr>
        <tr>
            <td align="center">
                @Model.TAuthFormEntity.TravellMeans
            </td>
            <td align="left">
                @Model.TAuthFormEntity.Currency.ShortName
            </td>
        </tr>
        <tr>
            <th>
                Purpose of Travel:
            </th>
            <td colspan="2">@Model.TAuthFormEntity.TravelPurpose
            </td>
        </tr>
        <tr>
            <th>
                Remarks:
            </th>
            <td colspan="2">@Model.TAuthFormEntity.Remarks
            </td>
        </tr>
    </table>
    <br />
    <p id="budgetCheckStatus"></p>
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th style="width: 10%;">
                Travel Dates
            </th>
            <th style="width: 14%;">
                Destination
            </th>
            <th style="width: 10%;">
                No. Of Nights
            </th>
            <th style="width: 10%;">
                Per Diem/Daily Allowance Rate
            </th>
            <th style="width: 10%;">
                Total Allowance Rate
            </th>
            <th style="width: 10%;">
                Advance Required
            </th>
            <th style="width: 10%;">
                Currency
            </th>
            <th style="width: 12%;">
                Project No
            </th>
            <th style="width: 12%;">
                Budget Line
            </th>
        </tr>
        @{string rowId = "row"; string blDiv = "blDiv"; int rowCount = 0;}
        @for (int i = 0; i < Model.ViewTravelDates.Count; i++)
        {
            rowId = "row" + i;
            blDiv = "blDiv" + rowCount;
            <tr id="@rowId">
                <td align="center">
                    @Model.ViewTravelDates[i].EntityTDate.TravalDate.Value.ToString("dd/MM/yyyy")
                    @Html.HiddenFor(m => Model.ViewTravelDates[i].EntityTDate.Id)
                </td>
                <td>
                    @Model.ViewTravelDates[i].EntityTDate.Destination
                </td>
                <td>
                    @Html.TextBoxFor(m => Model.ViewTravelDates[i].EntityTDate.NoOfNights, new { id = "night" + i, @class = "numericTb", onblur = "calculateTAFAllowance(" + i + ")" })
                </td>
                <td align="right">
                    @Html.TextBoxFor(m => Model.ViewTravelDates[i].EntityTDate.DailyPDRate, new { id = "dailyRate" + i, @class = "numericTb", onblur = "calculateTAFAllowance(" + i + ")" })
                </td>
                <td align="right">
                    @Html.TextBoxFor(m => Model.ViewTravelDates[i].EntityTDate.TotalAllowance, new { id = "totalAllowance" + i, @class = "numericTb", @readonly = "readonly" })
                </td>
                <td align="right">
                    @Html.TextBoxFor(m => Model.ViewTravelDates[i].EntityTDate.AdvanceRequired, new { id = "advanceRequired" + i, @class = "numericTb", onblur = "calculateTotalsTAF();checkBalance4TAF(document.getElementById('ViewTravelDates_" + i + "__EntityTDate_BudgetLineId'), " + i + ", 1)" })
                </td>
                <td align="center">
                    @Model.TravelDates[i].Currency.ShortName
                    @Html.HiddenFor(m => Model.TravelDates[i].Currency.Id, new { id = "currencyId" + rowCount })
                </td>
                <td align="center">
                    @Html.DropDownListFor(m => Model.ViewTravelDates[i].ProjectId, Model.ViewTravelDates[i].ProjectNos, new { onchange = "selectedIndexChange4TAF(this," + rowCount + ", 1, " + i + ")" })
                </td>
                <td align="center" id="@blDiv">
                    @Html.DropDownListFor(m => Model.ViewTravelDates[i].EntityTDate.BudgetLineId, Model.ViewTravelDates[i].BudgetLines, new { onchange = "javascript:checkBalance4TAF(this, " + i + ", 1)" })
                </td>
            </tr>
               rowCount++;
        }
    </table>
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <th style="width: 34%;">
                Description of other anticipated Expenses
            </th>
            <th style="width: 14%;" colspan="2">
                Total cost of Expenses
            </th>
            <th style="width: 14%;">
                Advance Required
            </th>
            <th style="width: 12%;">
                Currency
            </th>
            <th style="width: 12%;">
                Project No
            </th>
            <th style="width: 12%;">
                Budget Line
            </th>
        </tr>
        @for (int i = 0; i < Model.ViewTravelExpenses.Count; i++)
        {
            rowId = "rowExp" + i;
            blDiv = "blDiv" + rowCount;
            <tr id="@rowId">
                <td>
                    @Model.ViewTravelExpenses[i].EntityTExpense.ExpenseDescription
                    @Html.HiddenFor(m => Model.ViewTravelExpenses[i].EntityTExpense.Id)
                </td>
                <td align="right" colspan="2">
                    @Html.TextBoxFor(m => Model.ViewTravelExpenses[i].EntityTExpense.TotalCost, new { id = "totalExpense" + i, @class = "numericTb" })
                </td>
                <td align="right">
                    @Html.TextBoxFor(m => Model.ViewTravelExpenses[i].EntityTExpense.AdvanceRequired, new { id = "totalExpenseAdvance" + i, @class = "numericTb", onblur = "calculateTotalsTAF();checkBalance4TAF(document.getElementById('ViewTravelExpenses_" + i + "__EntityTExpense_BudgetLineId'), " + i + ", 0)" })
                </td>
                <td align="center">
                    @Model.ViewTravelExpenses[i].EntityTExpense.Currency.ShortName
                    @Html.HiddenFor(m => Model.ViewTravelExpenses[i].EntityTExpense.Currency.Id, new { id = "currencyId" + rowCount })
                </td>
                <td align="center">
                    @Html.DropDownListFor(m => Model.ViewTravelExpenses[i].ProjectId, Model.ViewTravelExpenses[i].ProjectNos, new { onchange = "selectedIndexChange4TAF(this," + rowCount + ", 0, " + i + ")" })
                </td>
                <td align="center" id="@blDiv">
                    @Html.DropDownListFor(m => Model.ViewTravelExpenses[i].EntityTExpense.BudgetLineId, Model.ViewTravelExpenses[i].BudgetLines, new { onchange = "javascript:checkBalance4TAF(this, " + i + ", 0)" })
                </td>
            </tr>
               rowCount++;
        }
        <tr>
            <th colspan="3" rowspan="2" class="gridheader" align="right">
                Total advance required for Per Diem/daily allowance & other anticipated expenses
            </th>
            <th align="center">
                Total Advance Required
            </th>
            <th class="gridheader" align="right">
                Currency
            </th>
            <th colspan="2" rowspan="2" class="gridheader">
            </th>
        </tr>
        <tr>
            <td align="right">
                @Html.TextBoxFor(m => m.TAuthFormEntity.TotalAmount, new { id = "totalVal", @class = "numericTb", @readonly = "readonly" })
            </td>
            <td align="center">
                @Model.TAuthFormEntity.Currency.ShortName
                <input type="hidden" id="currencyId" value="@Model.TAuthFormEntity.Currency.Id" />
            </td>
        </tr>
        <tr>
            <td class="gridheader2" align="right">
                Master Budget Currency:&nbsp;
            </td>
            <td align="center">
                @Html.DropDownListFor(m => m.MBCurrencyId, Model.Currencies, new { id = "mbCurrencyId", onchange = "calculateMBValue()" })
            </td>
            <td class="gridheader2" align="right">
                Total:&nbsp;
            </td>
            <td align="right">
                @Html.TextBoxFor(m => m.MBValue, new { id = "mbValue", @class = "numericTb" })
                <input type="hidden" id="origLocalValue" />
                <input type="hidden" id="origFxValue" />
            </td>
            <td class="gridheader2" colspan="3">
                &nbsp;TAF Value
            </td>
        </tr>
    </table>
    <br />
    <table width="98%" align="center" cellspacing="0" cellpadding="0" border="1" class="cardTable">
        <tr class="gridheader">
            <td width="19%">
                Authorization
            </td>
            <td width="27%">
                TAF Request Prepared by
            </td>
            <td width="27%">
                Finance Review/Approval of BL/PN
            </td>
            <td width="27%">
                TAF Authorized by Manager/CD
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                Name:
            </td>
            <td>
                @Model.PreparedBy.StaffName
            </td>
            <td>
                @if (Model.ApprovedBy != null)
                {
                    @Model.ApprovedBy.StaffName
                }
            </td>
            <td>
                @if (Model.AuthorizedBy != null)
                {
                    @Model.AuthorizedBy.StaffName
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                Title:
            </td>
            <td>
                @Model.PreparedBy.Designation
            </td>
            <td>
                @if (Model.ApprovedBy != null)
                {
                    @Model.ApprovedBy.Designation
                }
            </td>
            <td>
                @if (Model.AuthorizedBy != null)
                {
                    @Model.AuthorizedBy.Designation
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                Date:
            </td>
            <td>
                @Model.TAuthFormEntity.PreparedOn.Value.ToString("dd/MM/yyyy h:mm tt")
            </td>
            <td>
                @if (Model.ApprovedBy != null)
                {
                    @Model.TAuthFormEntity.ReviewedOn.Value.ToString("dd/MM/yyyy h:mm tt")
                }
            </td>
            <td>
                @if (Model.AuthorizedBy != null)
                {
                    @Model.TAuthFormEntity.AuthorizedOn.Value.ToString("dd/MM/yyyy h:mm tt")
                }
            </td>
        </tr>
        <tr>
            <td class="gridheader">
                Signature:
            </td>
            <td>
                @if (Model.PreparedBy.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.PreparedBy.PersonID, area = "" })" alt="" style="max-width: 100px;" />
                }
            </td>
            <td>
                @if (Model.ApprovedBy != null && Model.ApprovedBy.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.PreparedBy.PersonID, area = "" })" alt="" style="max-width: 100px;" />
                }
            </td>
            <td>
                @if (Model.AuthorizedBy != null && Model.AuthorizedBy.SignatureImage != null)
                { 
                    <img src="@Url.Action("Photo", "Person", new { id = Model.AuthorizedBy.PersonID, area = "" })" alt="" style="max-width: 100px;" />
                }
            </td>
        </tr>
    </table>
    <br />
    <table align="center" width="98%">
        <tr>
            <td align="right" width="50%"><input type="submit" class="btn tertiary" value="Authorize" /></td>
            <td width="50%">
                <input type="button" class="btn tertiary" value=" Reject " onclick="sendRequest('/RequestReview/LoadRejectTAF/@Model.TAuthFormEntity.Id', 'popup-page', 'popup-loading'); CenterPopup();" />
            </td>
        </tr>
    </table>
}
